// 链表的类

export class ListNode {

  constructor(val) {
    this.val = val,
      this.next = null
  }

  create(arr) {
    if (!Array.isArray(arr) || !arr.length) {
      return new ListNode(null)
    }
    let head = new ListNode(null)
    let cur = head
    for (let i = 0; i < arr.length; i++) {
      cur.next = new ListNode(arr[i])
      cur = cur.next
    }
    return head.next
  }

  display(link) {
    let arr = []
    let head = link
    let p = head
    while (p !== null) {
      arr.push(p.val)
      p = p.next
    }
    return arr.join('-->')
  }
}

